<template>
    <div class="app-container">
        <!-- <PageHeader :border="false" title="办案中心使用申请"/> -->
        <el-form ref="queryParamsRef" :inline="true" :model="queryParams">
            <el-row :gutter="20">
                <el-col :span="6">
                    <el-form-item label="办案单位名称" prop="depname">
                        <el-input v-model="queryParams.unitname" clearable @clear="getBAApplyLists"
                        @keydown.enter.prevent="getBAApplyLists" style="width:250px"/>
                    </el-form-item>
                </el-col>
                <el-col :span="7">
                    <el-form-item label="申请日期起止">
                        <el-date-picker
                            v-model="searchTime"
                            type="daterange"
                            range-separator="-"
                            start-placeholder="开始时间"
                            end-placeholder="截止时间"
                            value-format="YYYY-MM-DD"
                            @change="changeDateTimerHandle"
                            style="width:250px"
                        />
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label="状态">
                        <el-select
                            v-model="queryParams.state"
                            placeholder="选择状态"
                            clearable
                            @change="getBAApplyLists"
                            style="width:250px"
                        >
                            <el-option
                                v-for="item in nj_apply_status"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            />
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="5">
                    <el-form-item>
                        <el-button type="primary" @click="getBAApplyLists">
                            <el-icon class="me-1">
                                <Search/>
                            </el-icon>
                            查询
                        </el-button>
                    </el-form-item>
                    <el-form-item>
                        <el-button @click="handleRest(queryParamsRef)">
                            <el-icon class="me-1">
                                <Refresh/>
                            </el-icon>
                            重置
                        </el-button>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        <el-divider class="mt-0 mb-3"/>
        <el-row class="mb-3">
            <el-col :span="24">
                <el-space>
                    <el-button
                        type="primary" plain
                        @click="AddEditBAApplyRef.showAddBAApply('办案中心申请信息填写','add','1')">
                        <el-icon class="me-2">
                            <Plus/>
                        </el-icon>
                        新增
                    </el-button>
                </el-space>
            </el-col>
        </el-row>
        <el-table
            ref="BAApplyRef"
            v-loading="loading"
            :data="BAApplyTables"
            @selectionChange="selectChangeHandle"
            @row-dblclick="handleRowDblClick"
            stripe
            :row-style="tableRowStyle"
            show-overflow-tooltip
            border
        >
            <el-table-column label="办案单位名称" prop="unitname" />
            <el-table-column label="办案单位部门" prop="depname" />
            <el-table-column label="申请日期" prop="adddate"/>
            <el-table-column label="承办人" prop="asker_id"/>
            <el-table-column label="警务区名称" prop="policeareaname"/>
            <el-table-column label="申请进入时间" prop="startdate"/>
            <el-table-column label="预计离开时间" prop="enddate"/>
            <!-- <el-table-column label="办案部门审批领导" prop="approvaldetail"  width="140" /> -->
            <!-- <el-table-column label="状态" prop="state"  width="120"/> -->
            <el-table-column label="状态" prop="state" width="120">
                <template #default="scope">
                    <dict-tag :options="nj_apply_status" :value="scope.row.state" />
                </template>
            </el-table-column>
            <el-table-column fixed="right" label="操作" width="200">
                <template #default="scope">
                    <el-button
                        link size="small"
                        type="primary"
                        @click="AddEditBAApplyRef.showEditBAApply(scope.row,'修改办案中心申请信息','Edit','1')"
                        >
                        <el-icon class="me-1">
                            <Edit/>
                        </el-icon>
                        编辑
                    </el-button>
                    <el-button
                        link size="small"
                        type="primary"
                        @click="AddEditBAApplyRef.showEditBAApply(scope.row,'办案中心申请信息','See','1')"
                        >
                        <el-icon class="me-1">
                            <View/>
                        </el-icon>
                        详情
                    </el-button>
                    <el-button
                        link size="small"
                        type="danger"
                        @click="removeBAApply(scope.row)"
                    >
                        <el-icon class="me-1">
                            <Delete/>
                        </el-icon>
                        删除
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <pagination
            v-show="total > 0"
            v-model:page="paging.pageNum"
            v-model:limit="paging.pageSize"
            :total="total"
            @pagination="getBAApplyLists"
        />
        <AddEditBAApplyReg ref="AddEditBAApplyRef" @getBAApplyList="getBAApplyLists"  />
    </div>
</template>

<script setup>
import {ElMessageBox} from 'element-plus'
import PageHeader from "@/components/PageHeader/index.vue";
import AddEditBAApplyReg from "@/components/BAApplyReg/BAApplyReg.vue";

import {getCurrentInstance} from "vue";

import {BAApplyList, deleteBAApply} from "@/api/BAApply/BAApply";
import PageEnum from "@/enum/PageEnum.js";
const {proxy} = getCurrentInstance();
const {nj_anjian_type,nj_apply_status} = proxy.useDict('nj_anjian_type', 'nj_apply_status')

const queryParamsRef = ref()
const deleteStatus = ref(true)
const AddEditBAApplyRef = ref({})

const loading = ref(false)

const paging = ref({
    // 页码
    pageNum: 1,
    // 分页数量
    pageSize: PageEnum.SIZE
})
const queryParams = ref({
    type:1
})
const searchTime = ref([])
const total = ref(0)
const BAApplyTables = ref([])

onMounted(() => {
    getBAApplyLists()
})
const tableRowStyle = ({ row, rowIndex }) => {
    if (rowIndex % 2 === 0) {
        return { backgroundColor: '#e6ecff' }; // 偶数行背景色
    }
    return {}; // 奇数行默认透明
}
// 获取调解室房间列表
const getBAApplyLists = async () => {
    loading.value = true
    await BAApplyList(queryParams.value, paging.value).then(res => {
        BAApplyTables.value = res.rows
        total.value = res.total
        loading.value = false
    })
}
const BAApplyRef = ref()
const selectChangeHandle = (data) => {
    deleteStatus.value = data.length === 0;
}
const handleRowDblClick = (row) => {
    AddEditBAApplyRef.value.showEditBAApply(row,'办案中心申请信息','See','1')
}

const removeBAApply = async (row) => {
    ElMessageBox.confirm('确定删除此申请？', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    deleteBAApply(row.jw_apply_id).then(res => {
        getBAApplyLists()
    })
  }).catch(() => {
  });
}
// 改变时间
const changeDateTimerHandle = (date) => {
    console.log(date)
    if (date) {
        queryParams.value = {
            ...queryParams.value,
            params: {
                beginTime: date[0],
                endTime: date[1]
            }
        }
    } else {
        queryParams.value = {
            ...queryParams.value,
            params: {
                beginTime: '',
                endTime: ''
            }
        }
    }
    getBAApplyLists()
}
// 重置搜索调解
const handleRest = (formEl) => {
    queryParams.value = {
        type:1
    }
    getBAApplyLists()
}
</script>

<style lang="scss" scoped>
/* 保留斑马纹的同时添加悬停效果 */
:deep().el-table--striped .el-table__body tr.el-table__row--striped:hover td {
  background-color: #a5b8f4; /* 悬停时的红色 */
}

:deep().el-table__body tr:hover td {
  background-color: #a5b8f4; /* 悬停时的红色 */
}
</style>